import {reqbanner} from '../../request/api'
//初始状态
const initState={
        banner:[]
}

//TYPES
const TYPES={
        CHANGE_BANNER:'CHANGE_BANNER'
}

//reducer
const reducer =(state=initState,action)=>{
        switch(action.type){
                case TYPES.CHANGE_BANNER:
                        return{
                                ...state,
                                banner:action.banner
                        }
                default:
                        return state
        }
}

//creators 做逻辑 方法  请求
export const actions={
        cahngeBanner:banner=>({type:TYPES.CHANGE_BANNER,banner}),
        requestBanner:()=>(dispatch,getState)=>{
                reqbanner().then(res=>{
                      dispatch(actions.cahngeBanner(res.data.list))  
                })
        }
}

// 导出数据给组件
export const getBanner=state=>state.mine.banner
// 导出reducer
export default reducer